<template>
  <div class="dashboard-container">
    <h1 class="dashboard-title">医疗众包项目</h1>
    <div v-if="!isAuthenticated" class="auth-info-banner">
      您当前以访客身份查看项目列表。<router-link to="/login">登录</router-link> 或 <router-link to="/register">注册</router-link> 后可参与项目。
    </div>
    
    <!-- 加载和错误处理 -->
    <div v-if="loading" class="loading-container">
      <div class="spinner"></div>
      <p>加载项目中...</p>
    </div>
    
    <div v-else-if="error" class="error-container">
      <p>{{ error }}</p>
      <button @click="fetchProjects" class="retry-button">重试</button>
    </div>
    
    <div v-else>
      <!-- 用户角色标识和筛选选项 -->
      <div class="user-role-banner">
        <div class="role-indicator">
          <i class="el-icon-user"></i> 
          <span>您的身份：<strong :class="roleClass">{{ userRoleText }}</strong></span>
        </div>
        
        <!-- 研究者可以筛选查看自己创建的项目 -->
        <div v-if="isResearcher" class="project-filter">
          <span>项目筛选：</span>
          <div class="filter-options">
            <button 
              :class="['filter-btn', { active: filterMode === 'all' }]" 
              @click="setFilterMode('all')"
            >
              全部项目
            </button>
            <button 
              :class="['filter-btn', { active: filterMode === 'mine' }]" 
              @click="setFilterMode('mine')"
            >
              我的项目
            </button>
          </div>
        </div>
        
        <!-- 参与者特有的筛选选项 -->
        <div v-else-if="isAuthenticated && !isResearcher" class="project-filter">
          <span>项目筛选：</span>
          <div class="filter-options">
            <button 
              :class="['filter-btn', { active: filterMode === 'all' }]" 
              @click="setFilterMode('all')"
            >
              可参与项目
            </button>
            <button 
              :class="['filter-btn', { active: filterMode === 'participating' }]" 
              @click="setFilterMode('participating')"
            >
              我参与的项目
            </button>
          </div>
        </div>
      </div>
      
      <!-- 项目列表 -->
      <div class="projects-header">
        <button v-if="isAuthenticated && isResearcher" @click="showCreateModal = true" class="create-button">
          <i class="el-icon-plus"></i> 创建新项目
        </button>
      </div>
      
      <div v-if="filteredProjects.length === 0" class="no-projects">
        <p>暂无项目{{ isAuthenticated && isResearcher ? '，点击"创建新项目"按钮开始吧！' : '' }}</p>
      </div>
      
      <div v-else class="project-list">
        <div v-for="project in filteredProjects" :key="project.id" class="project-card">
          <div class="project-header">
            <h2 class="project-title">{{ project.title || '未命名项目' }}</h2>
            <div :class="['status-badge', getStatusClass(project)]">
              {{ getStatusText(project) }}
            </div>
          </div>
          
          <div class="project-info">
            <div class="info-section">
              <h4 class="section-title">项目简介</h4>
              <p class="project-description">{{ truncateText(project.description, 120) || '暂无描述' }}</p>
            </div>
            
            <div class="info-section">
              <h4 class="section-title">项目信息</h4>
              <div class="info-grid">
                <div class="info-item">
                  <i class="el-icon-user"></i>
                  <span class="info-label">研究者:</span>
                  <span class="info-value">{{ project.researcherInfo || '未指定' }}</span>
                </div>
                
                <div class="info-item">
                  <i class="el-icon-time"></i>
                  <span class="info-label">创建于:</span>
                  <span class="info-value">{{ formatDate(project.createdAt) }}</span>
                </div>
                
                <div class="info-item">
                  <i class="el-icon-edit-outline"></i>
                  <span class="info-label">最后更新:</span>
                  <span class="info-value">{{ formatDate(project.updatedAt) }}</span>
                </div>
                
                <div v-if="project.affiliationInfo" class="info-item">
                  <i class="el-icon-office-building"></i>
                  <span class="info-label">所属机构:</span>
                  <span class="info-value">{{ project.affiliationInfo }}</span>
                </div>
              </div>
            </div>
          </div>
          
          <div class="project-actions">
            <button @click="viewProject(project.id)" class="action-button view-button">
              <i class="el-icon-view"></i> 查看详情
            </button>
            
            <!-- 只有已登录的研究者才能编辑自己的项目 -->
            <button 
              v-if="isAuthenticated && isResearcher && !project.isDeleted && !project.isCompleted && canEditProject(project.researcherId)" 
              @click="editProject(project.id)" 
              class="action-button edit-button">
              <i class="el-icon-edit"></i> 编辑
            </button>
            
            <!-- 只有已登录的研究者才能删除自己的项目 -->
            <button 
              v-if="isAuthenticated && isResearcher && !project.isDeleted && canDeleteProject(project.researcherId)" 
              @click="confirmDelete(project)" 
              class="action-button delete-button">
              <i class="el-icon-delete"></i> 删除
            </button>
            
            <!-- 参与者特有按钮 -->
            <button 
              v-if="isAuthenticated && !isResearcher && !project.isDeleted && !project.isCompleted" 
              @click="contributeToProject(project.id)" 
              class="action-button contribute-button">
              <i class="el-icon-upload"></i> 贡献数据
            </button>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 创建项目弹窗 -->
    <div v-if="showCreateModal" class="modal">
      <div class="modal-content">
        <div class="modal-header">
          <h3>创建新医疗众包项目</h3>
          <button class="close-btn" @click="showCreateModal = false">&times;</button>
        </div>
        <div class="modal-body">
          <form @submit.prevent="createProject">
            <div class="form-group">
              <label for="projectTitle">项目标题 *</label>
              <input 
                type="text" 
                id="projectTitle" 
                class="form-control" 
                v-model="newProject.title" 
                required
              />
            </div>
            
            <div class="form-group">
              <label for="projectDescription">项目描述 *</label>
              <textarea 
                id="projectDescription" 
                class="form-control" 
                v-model="newProject.description" 
                rows="4" 
                required
              ></textarea>
            </div>
            
            <div class="form-group">
              <label for="researcherName">研究人员姓名 *</label>
              <input 
                type="text" 
                id="researcherName" 
                class="form-control" 
                v-model="newProject.researcherName" 
                required
              />
            </div>
            
            <div class="form-group">
              <label for="affiliationInfo">所属机构 *</label>
              <input 
                type="text" 
                id="affiliationInfo" 
                class="form-control" 
                v-model="newProject.affiliationInfo" 
                required
              />
            </div>
            
            <div class="form-group">
              <label for="contactInfo">联系方式 *</label>
              <input 
                type="text" 
                id="contactInfo" 
                class="form-control" 
                v-model="newProject.contactInfo" 
                required
              />
            </div>
            
            <div class="form-group">
              <label for="dataRequirements">数据需求 *</label>
              <textarea 
                id="dataRequirements" 
                class="form-control" 
                v-model="newProject.dataRequirements" 
                rows="3" 
                required
              ></textarea>
            </div>
            
            <div class="form-group">
              <label for="ethicalApproval">伦理审批文件编号</label>
              <input 
                type="text" 
                id="ethicalApproval" 
                class="form-control" 
                v-model="newProject.ethicalApproval"
              />
            </div>
            
            <div class="form-actions">
              <button 
                type="button" 
                class="btn btn-secondary" 
                @click="showCreateModal = false"
              >
                取消
              </button>
              <button 
                type="submit" 
                class="btn btn-primary" 
                :disabled="isCreating"
              >
                {{ isCreating ? '创建中...' : '创建项目' }}
              </button>
            </div>
          </form>
        </div>
      </div>
    </div>
    
    <!-- 删除确认弹窗 -->
    <div v-if="showDeleteConfirm" class="modal">
      <div class="modal-content">
        <div class="modal-header">
          <h3>确认删除项目</h3>
          <button class="close-btn" @click="showDeleteConfirm = false">&times;</button>
        </div>
        <div class="modal-body">
          <p>您确定要删除 <strong>{{ projectToDelete?.title }}</strong> 吗？此操作不可逆。</p>
          <div class="form-group">
            <label for="deleteReason">删除原因:</label>
            <textarea id="deleteReason" class="form-control" v-model="deleteReason" rows="3" placeholder="请输入删除原因"></textarea>
          </div>
        </div>
        <div class="form-actions">
          <button class="btn btn-secondary" @click="showDeleteConfirm = false">取消</button>
          <button class="btn btn-danger" @click="submitDelete" :disabled="!deleteReason.trim()">
            {{ isDeleting ? '删除中...' : '确认删除' }}
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'

export default {
  name: 'Dashboard',
  data() {
    return {
      loading: true,
      error: null,
      projects: [],
      statistics: null,
      showCreateModal: false,
      isCreating: false,
      newProject: {
        title: '',
        description: '',
        researcherName: '',
        affiliationInfo: '',
        contactInfo: '',
        dataRequirements: '',
        ethicalApproval: ''
      },
      projectToDelete: null,
      showDeleteConfirm: false,
      deleteReason: '',
      isDeleting: false,
      activeTab: 'active',
      filterMode: 'all' // 默认显示所有项目
    }
  },
  computed: {
    ...mapGetters({
      // 从auth模块映射getters
      isAuthenticated: 'auth/isAuthenticated',
      isResearcher: 'auth/isResearcher',
      currentUser: 'auth/currentUser'
    }),
    ...mapGetters([
      'isAdmin',
      'canEditProject',
      'canDeleteProject'
    ]),
    ...mapGetters('projects', [
      'allProjects',
      'activeProjects',
      'completedProjects'
    ]),
    
    userRoleText() {
      if (!this.currentUser) return '未知';
      return this.currentUser.role === 1 ? '研究者' : '数据贡献者';
    },
    
    roleClass() {
      if (!this.currentUser) return '';
      return this.currentUser.role === 1 ? 'role-researcher' : 'role-contributor';
    },
    
    // 当前用户创建的项目
    createdProjects() {
      // 在实际应用中，可能需要从API获取用户创建的项目
      // 这里暂时从所有项目中筛选，实际应用中应该由后端过滤
      return this.allProjects.filter(p => p.creatorId === this.currentUser?.id);
    },
    
    // 当前用户参与的项目
    userProjects() {
      // 在实际应用中，应该从API获取用户参与的项目
      // 这里暂时展示所有项目，实际应用中应该由后端过滤
      return this.allProjects.filter(p => p.status === 'ACTIVE');
    },
    
    filteredProjects() {
      const projects = this.$store.state.projects || [];
      
      // 根据筛选模式过滤项目
      if (this.filterMode === 'mine' && this.isResearcher && this.currentUser) {
        // 只显示当前用户创建的项目
        return projects.filter(p => p.creatorId === this.currentUser.id);
      } 
      else if (this.filterMode === 'participating' && !this.isResearcher && this.currentUser) {
        // 显示用户参与的项目（需要后端支持）
        // 这里假设有一个 participants 数组包含参与者ID
        return projects.filter(p => 
          p.participants && p.participants.includes(this.currentUser.id)
        );
      }
      
      // 默认返回所有项目
      return projects;
    },
    
    canEditProject() {
      return (researcherId) => {
        if (!this.isAuthenticated || !this.isResearcher) return false;
        return this.currentUser && (this.currentUser.id === researcherId || this.currentUser.isAdmin);
      };
    },
    
    canDeleteProject() {
      return (researcherId) => {
        if (!this.isAuthenticated || !this.isResearcher) return false;
        return this.currentUser && (this.currentUser.id === researcherId || this.currentUser.isAdmin);
      };
    }
  },
  created() {
    this.fetchProjects();
  },
  
  async mounted() {
    // 添加路由进入事件监听，确保从其他页面返回时刷新数据
    // eslint-disable-next-line no-unused-vars
    this.$router.afterEach((to, from) => {
      if (to.name === 'dashboard') {
        console.log('Dashboard路由被激活，刷新数据');
        this.fetchProjects();
      }
    });
  },
  
  methods: {
    ...mapActions('projects', [
      'fetchProjects', 
      'fetchProjectStatistics',
      'deleteProject'
    ]),
    
    async fetchProjects() {
      this.loading = true;
      this.error = null;
      try {
        await this.$store.dispatch('fetchProjects');
      } catch (error) {
        this.error = '加载项目失败，请稍后重试';
        console.error('获取项目列表失败:', error);
      } finally {
        this.loading = false;
      }
    },
    
    formatDate(dateString) {
      if (!dateString) return '未知日期';
      
      try {
        const date = new Date(dateString);
        if (isNaN(date.getTime())) return '无效日期';
        
        return date.toLocaleString('zh-CN', {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit',
          hour: '2-digit',
          minute: '2-digit'
        }).replace(/\//g, '-');
      } catch (error) {
        console.error('日期格式化错误:', error);
        return '无效日期';
      }
    },
    
    getStatusText(project) {
      if (project.isDeleted) return '已删除';
      if (project.isCompleted) return '已完成';
      return '进行中';
    },
    
    getStatusClass(project) {
      if (project.isDeleted) return 'status-deleted';
      if (project.isCompleted) return 'status-completed';
      return 'status-active';
    },
    
    truncateText(text, maxLength) {
      if (!text) return '';
      if (text.length <= maxLength) return text;
      return text.substring(0, maxLength) + '...';
    },
    
    viewProject(id) {
      this.$router.push(`/project/${id}`);
    },
    
    editProject(id) {
      this.$router.push(`/edit-project/${id}`);
    },
    
    confirmDelete(project) {
      this.projectToDelete = project;
      this.showDeleteConfirm = true;
    },
    
    async submitDelete() {
      if (!this.projectToDelete) return;
      
      try {
        this.isDeleting = true;
        await this.deleteProject({
          id: this.projectToDelete.id,
          reason: this.deleteReason
        });
        this.showDeleteConfirm = false;
        this.projectToDelete = null;
        this.deleteReason = '';
        
        // 显示成功消息
        alert('项目删除成功');
      } catch (error) {
        console.error('删除项目失败:', error);
        alert('删除项目失败: ' + (error.response?.data || error.message || '未知错误'));
      } finally {
        this.isDeleting = false;
      }
    },
    
    // 统计数据相关方法
    getActiveProjectCount() {
      return this.statistics?.statusDistribution?.ACTIVE || 0;
    },
    
    getCompletedProjectCount() {
      return this.statistics?.statusDistribution?.COMPLETED || 0;
    },
    
    getHistoryTypeLabel(type) {
      switch(type) {
        case 'CREATE': return '创建';
        case 'UPDATE': return '更新';
        case 'COMPLETE': return '完成';
        case 'DELETE': return '删除';
        default: return type;
      }
    },
    
    getHistoryTypeColor(type) {
      switch(type) {
        case 'CREATE': return '#2ecc71';
        case 'UPDATE': return '#3498db';
        case 'COMPLETE': return '#9b59b6';
        case 'DELETE': return '#e74c3c';
        default: return '#95a5a6';
      }
    },
    
    getTotalHistoryTypeCount() {
      if (!this.statistics?.historyTypeDistribution) return 0;
      return Object.values(this.statistics.historyTypeDistribution).reduce((a, b) => a + b, 0);
    },
    
    getDistributionPercentage(count, total) {
      if (!total) return 0;
      return Math.round((count / total) * 100);
    },
    
    getHistoryProjectId(history) {
      if (history.details && Array.isArray(history.details) && history.details.length > 0) {
        return `项目${history.details[0]}`;
      }
      return '未关联项目';
    },
    
    getHistoryTypeText(history) {
      if (history.details && Array.isArray(history.details) && history.details.length > 1) {
        const typeCode = history.details[1];
        switch(parseInt(typeCode)) {
          case 0: return '创建';
          case 1: return '更新';
          case 2: return '完成';
          case 3: return '删除';
          default: return '未知操作';
        }
      }
      return '未知操作';
    },
    
    getHistoryTypeClass(history) {
      if (history.details && Array.isArray(history.details) && history.details.length > 1) {
        const typeCode = history.details[1];
        switch(parseInt(typeCode)) {
          case 0: return 'type-create';
          case 1: return 'type-update';
          case 2: return 'type-complete';
          case 3: return 'type-delete';
          default: return 'type-unknown';
        }
      }
      return 'type-unknown';
    },
    
    formatHistoryTime(history) {
      try {
        if (history.details && Array.isArray(history.details) && history.details.length > 2) {
          const timestamp = history.details[2];
          if (timestamp) {
            const date = new Date(parseInt(timestamp) * 1000);
            return date.toLocaleString('zh-CN', {
              year: 'numeric',
              month: '2-digit',
              day: '2-digit',
              hour: '2-digit',
              minute: '2-digit'
            }).replace(/\//g, '-');
          }
        }
      } catch (e) {
        console.error('时间格式化错误', e);
      }
      return '时间未记录';
    },
    
    // 创建新项目
    async createProject() {
      try {
        this.isCreating = true;
        
        // 构造请求数据 - 确保字段名前面带下划线符合API格式
        const projectData = {
          title: this.newProject.title,
          description: this.newProject.description,
          researcherInfo: this.newProject.researcherName
        };
        
        console.log('准备创建项目:', projectData);
        
        // 使用store action创建项目
        const response = await this.$store.dispatch('createProject', projectData);
        
        if (response && response.success) {
          // 创建成功
          this.showCreateModal = false;
          this.resetNewProjectForm();
          
          // 显示成功消息
          alert('项目创建成功');
        }
      } catch (error) {
        console.error('创建项目失败', error);
        alert('创建项目失败: ' + (error.response?.data || error.message || '未知错误'));
      } finally {
        this.isCreating = false;
      }
    },
    
    // 重置新项目表单
    resetNewProjectForm() {
      this.newProject = {
        title: '',
        description: '',
        researcherName: '',
        affiliationInfo: '',
        contactInfo: '',
        dataRequirements: '',
        ethicalApproval: ''
      };
    },
    
    contributeToProject(projectId) {
      this.$router.push(`/project/${projectId}`);
      // 可以在路由或导航后添加一个标记，以便项目详情页面自动打开贡献数据的模态框
    },
    
    // 设置项目筛选模式
    setFilterMode(mode) {
      this.filterMode = mode;
    }
  }
}
</script>

<style scoped>
.dashboard-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.dashboard-title {
  font-size: 28px;
  margin-bottom: 30px;
  color: #333;
  text-align: center;
}

/* 加载和错误状态 */
.loading-container, .error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
}

.spinner {
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  border-top: 4px solid #3498db;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.error-container {
  color: #e74c3c;
}

.retry-button {
  background-color: #3498db;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 10px;
}

/* 项目列表 */
.projects-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}

.create-button {
  background-color: #2ecc71;
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  display: flex;
  align-items: center;
}

.create-button i {
  margin-right: 8px;
}

.no-projects {
  text-align: center;
  padding: 40px;
  background-color: #f9f9f9;
  border-radius: 8px;
  color: #666;
}

.project-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 20px;
}

.project-card {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 20px;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s, box-shadow 0.2s;
}

.project-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.project-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.project-title {
  font-size: 24px;
  margin: 0;
  color: #333;
  font-weight: bold;
}

.status-badge {
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
}

.status-active {
  background-color: #3498db;
  color: white;
}

.status-completed {
  background-color: #27ae60;
  color: white;
}

.status-deleted {
  background-color: #e74c3c;
  color: white;
}

.project-info {
  margin-bottom: 15px;
}

.info-section {
  margin-bottom: 15px;
  border-top: 1px solid #eee;
  padding-top: 10px;
}

.section-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 10px;
  color: #555;
}

.project-description {
  color: #666;
  line-height: 1.5;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.info-item {
  display: flex;
  align-items: center;
}

.info-item i {
  margin-right: 8px;
  color: #3498db;
}

.info-label {
  font-size: 14px;
  color: #666;
  margin-right: 5px;
}

.info-value {
  font-size: 14px;
  font-weight: bold;
}

.project-actions {
  display: flex;
  gap: 10px;
}

.action-button {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  font-size: 14px;
}

.action-button i {
  margin-right: 5px;
}

.view-button {
  background-color: #3498db;
  color: white;
}

.edit-button {
  background-color: #f39c12;
  color: white;
}

.delete-button {
  background-color: #e74c3c;
  color: white;
}

.contribute-button {
  background-color: #2ecc71;
  color: white;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .project-list {
    grid-template-columns: 1fr;
  }
  
  .project-card {
    padding: 15px;
  }
  
  .project-title {
    font-size: 18px;
  }
}

/* 模态框样式 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  border-radius: 8px;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #f0f0f0;
}

.modal-header h3 {
  margin: 0;
  color: #2c3e50;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #7f8c8d;
}

.modal-body {
  padding: 20px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: #2c3e50;
}

.form-control {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

textarea.form-control {
  resize: vertical;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 30px;
}

.btn {
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

.btn-secondary {
  background-color: #f8f9fa;
  border: 1px solid #ddd;
  color: #333;
}

.btn-primary {
  background-color: #3498db;
  color: white;
  border: none;
}

.btn-danger {
  background-color: #e74c3c;
  color: white;
  border: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-info-banner {
  margin-bottom: 20px;
  padding: 12px 15px;
  background-color: #f8f9fa;
  border-left: 4px solid #3498db;
  border-radius: 4px;
  font-size: 0.95rem;
  color: #666;
}

.auth-info-banner a {
  color: #3498db;
  font-weight: 500;
  text-decoration: none;
}

.auth-info-banner a:hover {
  text-decoration: underline;
}

.user-role-banner {
  background-color: #f8f9fa;
  padding: 15px 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.role-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
}

.role-indicator i {
  color: var(--color-primary);
}

.role-researcher {
  color: var(--color-primary);
  font-weight: 600;
}

.role-participant {
  color: var(--color-accent);
  font-weight: 600;
}

.project-filter {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-options {
  display: flex;
  gap: 8px;
}

.filter-btn {
  background-color: #fff;
  border: 1px solid #ddd;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.filter-btn:hover {
  border-color: var(--color-primary-light);
}

.filter-btn.active {
  background-color: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

@media (max-width: 768px) {
  .user-role-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  
  .project-filter {
    width: 100%;
    justify-content: space-between;
  }
}
</style> 